package com.oauth.google.server.shared;

import java.util.ArrayList;
import java.util.List;

import com.google.gdata.data.Kind.AdaptorException;
import com.google.gdata.data.photos.GphotoEntry;
import com.google.gdata.data.photos.PhotoEntry;
import com.oauth.google.client.beans.picassa.GooglePicasaAlbum;
import com.oauth.google.client.beans.picassa.PicasaPhoto;

public class PicasaUtils {

	public static List<GooglePicasaAlbum> getPicasaAlbums(
			List<GphotoEntry> pAlbums) throws AdaptorException {
		ArrayList<GooglePicasaAlbum> picasaAlbums = new ArrayList<GooglePicasaAlbum>();

		System.out.println("Album size=" + pAlbums.size());
		if (pAlbums != null) {
			for (GphotoEntry entry : pAlbums) {
				picasaAlbums.add(convertToEntry(entry));
			}
		}
		return picasaAlbums;
	}

	public static List<PicasaPhoto> getPhotos(List<PhotoEntry> photos) {
		ArrayList<PicasaPhoto> picasaPhotos = new ArrayList<PicasaPhoto>();

		System.out.println("Photos size=" + picasaPhotos.size());
		if (photos != null) {
			for (PhotoEntry entry : photos) {
				picasaPhotos.add(convertToEntry(entry));
			}
		}
		return picasaPhotos;

	}

	private static GooglePicasaAlbum convertToEntry(GphotoEntry pEntry) {
		GooglePicasaAlbum album = new GooglePicasaAlbum();
		album.setTitle(pEntry.getTitle().getPlainText());
		album.setAlbumId(pEntry.getGphotoId());
		return album;
	}

	private static PicasaPhoto convertToEntry(PhotoEntry pEntry) {
		PicasaPhoto photo = new PicasaPhoto();
		photo.setLink(pEntry.getMediaThumbnails().get(0).getUrl());
		photo.setId(pEntry.getId());
		System.out.println(pEntry.getTitle().getPlainText());
		return photo;
	}

}
